﻿using System;
using System.Web;
using System.ServiceModel;

//自定义命名空间
using DreamCube.Foundation.Basic.Objects.Log;

namespace DC_52Icon.ImageWeb
{
    /// <summary>
    /// image 的摘要说明
    /// </summary>
    public class image : IHttpHandler
    {
        private static PicWCFService.PicServiceClient client = new PicWCFService.PicServiceClient();
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                if (client.State == CommunicationState.Faulted)
                    client = new PicWCFService.PicServiceClient();

                String imageID = context.Request.QueryString["id"];
                Int64 id;
                if (!String.IsNullOrEmpty(imageID) && Int64.TryParse(imageID, out id))
                {
                    Byte[] imageData = client.GetImage(id);
                    context.Response.ContentType = "image/x-icon";
                    context.Response.OutputStream.Write(imageData, 0, imageData.Length);
                    context.Response.Flush();
                }
                else context.Response.Close();
            }
            catch (Exception ex)
            {
                LoggerManager.Logger.MakeLogAsync(ex);
            }
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}